#include <REGX52.H>
#include "Delay.h"
#include "Nixie.h"
#include "Timer0.h"
#include "dulianjian.h"

sbit LED=P2^0;
sbit DC_motor=P1^0;

unsigned char Counter,Comapare;	//Counter:计数器，定时自增 Comapare:比较值
unsigned char KeyNum,velocity;
	
void main()
{
	Timer0Init();		
	while(1)
	{
		KeyNum=dulianjian();
		if(KeyNum==1)
		{
			velocity++;
			velocity%=4;	//如果velocity小于4，velocity++，如果velocity>=4，velocity=0
			if(velocity==0){Comapare=0;}
			if(velocity==1){Comapare=30;}
			if(velocity==2){Comapare=60;}
			if(velocity==3){Comapare=100;}	//调整比较值改变占空比
		}
		Nixie(1,velocity);
	}
}

void Timer0_Rountine(void) interrupt 1
{
	TL0 = 0xA4;	
	TH0 = 0xFF;	
	Counter%=100;	//相当于Counter自加，加到100后又变为0
	if(Counter<Comapare)
	{
		LED=0;
		DC_motor=1;
	}
	else
	{
		LED=1;
		DC_motor=0;
	}
}